<%@ Page language="vb" CodeFile="printAllInvoice.aspx.vb" Inherits="printAllInvoice_aspx_vb" %>

<%
    rowNumber = 1
    subDo = Request.QueryString("subDo")
    If (Request.QueryString("do")) = Nothing Then 
        Over()
       
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%'>")
        Response.Write("<tr>")
        Response.Write("<td>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        Response.Write("<tr>")
        Response.Write("<td class='headline' colspan='15'>QUEUED PRINTOUTS - <a href='printAllInvoice.aspx?do=print'>[PRINT ALL]</a><hr class='hrHeadline'></td>")
        Response.Write("</tr>")
        

        Response.Write("<tr bgcolor='#eeeeee'>")
        Response.Write("<td class='formBold'>Invoice ID</td>")
        Response.Write("<td class='formBold'>References invoice ID</td>")
        Response.Write("<td class='formBold'>Partner</td>")
        Response.Write("<td class='formBold'>Contract number</td>")
        Response.Write("<td class='formBold'>Licence number</td>")
        Response.Write("<td class='formBold'>VIN-number</td>")
        Response.Write("<td class='formBold' align='right'>Invoice amount (Tax incl.)</td>")
        Response.Write("<td class='formBold' align='right'>Invoice claim (Tax incl.)</td>")
        Response.Write("<td class='formBold' align='right'>Invoice date</td>")
        Response.Write("<td class='formBold' align='right'>Expiry date</td>")
        Response.Write("<td class='formBold' align='right'>Days</td>")
        Response.Write("<td class='formBold' align='right'>Invoice printed</td>")
        Response.Write("<td class='formBold' align='right'>Country</td>")
        Response.Write("<td class='formBold' align='right'></td>")
        Response.Write("<td class='formBold' align='right'></td>")
        Response.Write("</tr>")
        dbOpen()
        RecSet = Conn.Execute("Select i.invoiceID, c.countryID,i.date, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, p.partnerName, c.country, c.countryCurrency, c.decimals, ic.invoiceClaim As invoiceCreditAmount, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoice i INNER JOIN tblPartner p ON p.partnerID = i.partnerID) INNER JOIN tblCountry c ON c.countryID = i.countryID) LEFT JOIN tblInvoiceCredit ic ON ic.invoiceID = i.invoiceID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                countryID = RecSet.Fields("countryID").Value
                __date = RecSet.Fields("date").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                invoiceCreditAmount = RecSet.Fields("invoiceCreditAmount").Value
                salesTax = RecSet.Fields("salesTax").Value
                
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                
                
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                If IsDBNull(invoiceCreditAmount) = false Then 
                    invoiceAmount = CDbl(invoiceAmount) - CDbl(invoiceCreditAmount)
                    invoiceClaim = CDbl(invoiceClaim) - CDbl(invoiceCreditAmount)
                End IF
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td></td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoice.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editInvoice.aspx?invoiceID=" & invoiceID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoicePriceListModificationID As invoiceID, i.invoiceAmount,i.date, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, p.partnerName, c.country, c.countryCurrency, c.decimals, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From ((tblInvoicePriceListModification i INNER JOIN tblPartner p ON p.partnerID = i.partnerID) INNER JOIN tblCountry c ON c.countryID = i.countryID) Where i.invoiceDate Is Not Null AND i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                __date = RecSet.Fields("date").Value
                salesTax = RecSet.Fields("salesTax").Value
                
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                
                
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td></td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoicePriceListModification.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editInvoicePriceListModification.aspx?invoiceID=" & invoiceID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceDurationPenaltyID As invoiceID, i.invoiceAmount,i.date, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, v.vehicleID, v.regnr, v.vinNumber, v.contractNumber, p.partnerName, c.country, c.countryCurrency, c.decimals, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoiceDurationPenalty i INNER JOIN tblVehicle v ON v.vehicleID = i.vehicleID) INNER JOIN tblPartner p ON p.partnerID = v.partnerID) INNER JOIN tblCountry c ON c.countryID = v.countryID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                __date = RecSet.Fields("date").Value
                salesTax = RecSet.Fields("salesTax").Value
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td></td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoiceDurationPenalty.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceCreditDurationPenaltyID As invoiceCreditID, i.invoiceDurationPenaltyID As invoiceID, i.date,i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, v.vehicleID, v.regnr, v.vinNumber, v.contractNumber, p.partnerName, c.country, c.countryCurrency, c.decimals, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoiceCreditDurationPenalty i INNER JOIN tblVehicle v ON v.vehicleID = i.vehicleID) INNER JOIN tblPartner p ON p.partnerID = v.partnerID) INNER JOIN tblCountry c ON c.countryID = v.countryID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceCreditID = RecSet.Fields("invoiceCreditID").Value
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                __date = RecSet.Fields("date").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                salesTax = RecSet.Fields("salesTax").Value
                
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceAmount = CDbl(invoiceAmount) * - 1
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                invoiceClaim = CDbl(invoiceClaim) * - 1
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceCreditID & "</td>")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoiceCreditDurationPenalty.aspx?invoiceID=" & invoiceCreditID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceDistancePenaltyID As invoiceID, i.invoiceAmount, i.date, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, v.vehicleID, v.regnr, v.vinNumber, v.contractNumber, p.partnerName, c.country, c.countryCurrency, c.decimals, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoiceDistancePenalty i INNER JOIN tblVehicle v ON v.vehicleID = i.vehicleID) INNER JOIN tblPartner p ON p.partnerID = v.partnerID) INNER JOIN tblCountry c ON c.countryID = v.countryID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                __date = RecSet.Fields("date").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                salesTax = RecSet.Fields("salesTax").Value
                
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td></td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoiceDistancePenalty.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceCreditDistancePenaltyID As invoiceCreditID, i.date, i.invoiceDistancePenaltyID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, v.vehicleID, v.regnr, v.vinNumber, v.contractNumber, p.partnerName, c.country, c.countryCurrency, c.decimals, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoiceCreditDistancePenalty i INNER JOIN tblVehicle v ON v.vehicleID = i.vehicleID) INNER JOIN tblPartner p ON p.partnerID = v.partnerID) INNER JOIN tblCountry c ON c.countryID = v.countryID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceCreditID = RecSet.Fields("invoiceCreditID").Value
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                __date = RecSet.Fields("date").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                salesTax = RecSet.Fields("salesTax").Value
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceAmount = CDbl(invoiceAmount) * - 1
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                invoiceClaim = CDbl(invoiceClaim) * - 1
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceCreditID & "</td>")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoiceCreditDistancePenalty.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceAdminFeeID As invoiceID, i.invoiceAmount,i.date, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, p.partnerName, c.country, c.countryCurrency, c.decimals, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From ((tblInvoiceAdminFee i INNER JOIN tblPartner p ON p.partnerID = i.partnerID) INNER JOIN tblCountry c ON c.countryID = i.countryID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                __date = RecSet.Fields("date").Value
                decimals = RecSet.Fields("decimals").Value
                salesTax = RecSet.Fields("salesTax").Value
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td></td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td>N/A</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoiceAdminFee.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editInvoiceAdminFee.aspx?invoiceID=" & invoiceID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceServiceAccountBalanceID As invoiceID,i.date, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, v.vehicleID, v.regnr, v.vinNumber, v.contractNumber, p.partnerName, c.country, c.countryCurrency, c.decimals, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoiceServiceAccountBalance i INNER JOIN tblVehicle v ON v.vehicleID = i.vehicleID) INNER JOIN tblPartner p ON p.partnerID = v.partnerID) INNER JOIN tblCountry c ON c.countryID = v.countryID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                __date = RecSet.Fields("date").Value
                salesTax = RecSet.Fields("salesTax").Value
                
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td></td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoiceServiceAccountBalance.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editInvoiceServiceAccountBalance.aspx?invoiceID=" & invoiceID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceCreditServiceAccountBalanceID As invoiceCreditID,i.date, i.invoiceServiceAccountBalanceID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, v.vehicleID, v.regnr, v.vinNumber, v.contractNumber, p.partnerName, c.country, c.countryCurrency, c.decimals, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoiceCreditServiceAccountBalance i INNER JOIN tblVehicle v ON v.vehicleID = i.vehicleID) INNER JOIN tblPartner p ON p.partnerID = v.partnerID) INNER JOIN tblCountry c ON c.countryID = v.countryID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceCreditID = RecSet.Fields("invoiceCreditID").Value
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                vehicleID = RecSet.Fields("vehicleID").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                __date = RecSet.Fields("date").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                salesTax = RecSet.Fields("salesTax").Value
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceCreditID & "</td>")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoiceCreditServiceAccountBalance.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editVehicle.aspx?vehicleID=" & vehicleID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceSeparateID As invoiceID,i.date, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, p.partnerName, c.country, c.countryCurrency, c.decimals, v.regnr, v.vinNumber, v.contractNumber, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoiceSeparate i INNER JOIN tblPartner p ON p.partnerID = i.partnerID) INNER JOIN tblCountry c ON c.countryID = i.countryID) LEFT JOIN tblVehicle v ON v.vehicleID = i.vehicleID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                 __date = RecSet.Fields("date").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                salesTax = RecSet.Fields("salesTax").Value
                
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If IsDBNull(regnr) = true Then 
                    regnr = "N/A"
                End IF
                If IsDBNull(vinNumber) = true Then 
                    vinNumber = "N/A"
                End IF
                If IsDBNull(contractNumber) = true Then 
                    contractNumber = "N/A"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td></td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td><a href='printInvoiceSeparate.aspx?invoiceID=" & invoiceID & "' target='_blank'>print</td>")
                Response.Write("<td><a href='editInvoiceSeparate.aspx?invoiceID=" & invoiceID & "'>details</td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        RecSet = Conn.Execute("Select i.invoiceCreditSeparateID As invoiceCreditID,i.date, i.invoiceSeparateID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.invoicePrinted, p.partnerName, c.country, c.countryCurrency, c.decimals, v.regnr, v.vinNumber, v.contractNumber, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax From (((tblInvoiceCreditSeparate i INNER JOIN tblPartner p ON p.partnerID = i.partnerID) INNER JOIN tblCountry c ON c.countryID = i.countryID) LEFT JOIN tblVehicle v ON v.vehicleID = i.vehicleID) Where i.invoiceDate Is Not Null And i.invoicePrinted = 0")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                invoiceCreditID = RecSet.Fields("invoiceCreditID").Value
                invoiceID = RecSet.Fields("invoiceID").Value
                invoiceAmount = RecSet.Fields("invoiceAmount").Value
                invoiceClaim = RecSet.Fields("invoiceClaim").Value
                invoiceDate = RecSet.Fields("invoiceDate").Value
                expiryDate = RecSet.Fields("expiryDate").Value
                invoicePrinted = RecSet.Fields("invoicePrinted").Value
                partnerName = RecSet.Fields("partnerName").Value
                country = RecSet.Fields("country").Value
                countryCurrency = RecSet.Fields("countryCurrency").Value
                decimals = RecSet.Fields("decimals").Value
                regnr = RecSet.Fields("regnr").Value
                vinNumber = RecSet.Fields("vinNumber").Value
                __date = RecSet.Fields("date").Value
                contractNumber = RecSet.Fields("contractNumber").Value
                salesTax = RecSet.Fields("salesTax").Value
                
                '**********************
                If countryID = 4 Then
                    If (__date <= Date.Parse("2010-06-30")) Then
                        salesTax = 22
                    ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                        salesTax = 23
                    Else
                        salesTax = 24
                    End If
                End If
                '**********************
                salesTax = salesTax + 100
                salesTax = CDbl(salesTax) / 100
                invoiceAmount = CDbl(invoiceAmount) * CDbl(salesTax)
                invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                invoiceAmount = CDbl(invoiceAmount)
                invoiceClaim = CDbl(invoiceClaim) * CDbl(salesTax)
                invoiceClaim = FormatNumber(CDbl(invoiceClaim), decimals)
                invoiceClaim = CDbl(invoiceClaim)
                totInvoiceAmount = totInvoiceAmount + invoiceAmount
                totInvoiceClaim = totInvoiceClaim + invoiceClaim
                expiryDays = DateDiff("d", Now(), Convert.ToDateTime(expiryDate))
                If expiryDays >= 0 Then 
                    expiryDays = "<font color='green'>" & expiryDays & "</font>"
                Else
                    expiryDays = "<font color='red'>" & expiryDays & "</font>"
                End IF
                If CInt(invoicePrinted) = 0 Then 
                    invoicePrinted = "<font color='red'>No</font>"
                Else
                    invoicePrinted = "<font color='green'>Yes</font>"
                End IF
                If IsDBNull(regnr) = true Then 
                    regnr = "N/A"
                End IF
                If IsDBNull(vinNumber) = true Then 
                    vinNumber = "N/A"
                End IF
                If IsDBNull(contractNumber) = true Then 
                    contractNumber = "N/A"
                End IF
                If rowNumber = 0 Then 
                    strGrey = " bgcolor='#eeeeee'"
                    rowNumber = 1
                Else
                    strGrey = ""
                    rowNumber = 0
                End IF
                Response.Write("<tr" & strGrey & ">")
                Response.Write("<td>" & invoiceCreditID & "</td>")
                Response.Write("<td>" & invoiceID & "</td>")
                Response.Write("<td>" & partnerName & "</td>")
                Response.Write("<td>" & contractNumber & "</td>")
                Response.Write("<td>" & regnr & "</td>")
                Response.Write("<td>" & vinNumber & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceAmount), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & FormatNumber(CDbl(invoiceClaim), 2) & " " & countryCurrency & "</td>")
                Response.Write("<td align='right'>" & invoiceDate & "</td>")
                Response.Write("<td align='right'>" & expiryDate & "</td>")
                Response.Write("<td align='right'>" & expiryDays & "</td>")
                Response.Write("<td align='right'>" & invoicePrinted & "</td>")
                Response.Write("<td align='right'>" & country & "</td>")
                Response.Write("<td align='right'></td>")
                Response.Write("<td align='right'></td>")
                Response.Write("</tr>")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        If rowNumber = 0 Then 
            strGrey = " bgcolor='#eeeeee'"
            rowNumber = 1
        Else
            strGrey = ""
            rowNumber = 0
        End IF
        Response.Write("<tr" & strGrey & ">")
        Response.Write("<td class='formBold'>Total sum:</td>")
        Response.Write("<td class='formBold' colspan='5'></td>")
        Response.Write("<td class='formBold' align='right'>" & FormatNumber(CDbl(totInvoiceAmount), 2) & " EUR</td>")
        Response.Write("<td class='formBold' align='right'>" & FormatNumber(CDbl(totInvoiceClaim), 2) & " EUR</td>")
        Response.Write("<td class='formBold' colspan='6'></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td colspan='15'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "print" Then 
        If subDo = "" Then 
            strInvoiceID = ""
            dbOpen()
            RecSet = Conn.Execute("Select invoiceID From tblInvoice Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoicePriceListModificationID As invoiceID From tblInvoicePriceListModification Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceDurationPenaltyID As invoiceID From tblInvoiceDurationPenalty Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceCreditDurationPenaltyID As invoiceID From tblInvoiceCreditDurationPenalty Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceDistancePenaltyID As invoiceID From tblInvoiceDistancePenalty Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceCreditDistancePenaltyID As invoiceID From tblInvoiceCreditDistancePenalty Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceAdminFeeID As invoiceID From tblInvoiceAdminFee Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceServiceAccountBalanceID As invoiceID From tblInvoiceServiceAccountBalance Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceCreditServiceAccountBalanceID As invoiceID From tblInvoiceCreditServiceAccountBalance Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            dbOpen()
            RecSet = Conn.Execute("Select invoiceSeparateID As invoiceID From tblInvoiceSeparate Where invoiceDate Is Not Null And invoicePrinted = 0")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    strInvoiceID = strInvoiceID & "," & invoiceID
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
            If Len(strInvoiceID) > 0 Then 
                strInvoiceID = Mid(strInvoiceID, 2, Len(strInvoiceID) - 1)
            End IF
        Else
            strInvoiceID = Request.QueryString("strInvoiceID")
        End IF
        OverPrint()
        Response.Write("<div class=noprint>")
        Response.Write("<table>")
        Response.Write("<tr>")
        Response.Write("<td class='headline'>")
        Response.Write("<form>")
        Response.Write("<input type='button' onClick='javascript:print();' value='Print'>&nbsp; ")
        If subDo = "" Then 
            Response.Write("<input type='button' value='Print invoice copy' onclick=""{location.href='printAllInvoice.aspx?do=print&subDo=invoiceCopy&strInvoiceID=" & strInvoiceID & "';} return false;"">")
        ElseIf subDo = "invoiceCopy" Then 
            Response.Write("<input type='button' value='Print invoice specification' onclick=""{location.href='printAllInvoice.aspx?do=printSpecification&strInvoiceID=" & strInvoiceID & "';} return false;"">")
        Else
            Response.Write("<font color='#fcbc00'>" & subDo & "</font>")
        End IF
        Response.Write("</form>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Response.Write("</div>")
        For invoiceType = 1 To 10
            If invoiceType = 1 Then 
                strSql = "SELECT i.invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoicePrinted, i.date, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, ic.invoiceAmount As invoiceCreditAmount, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM (((((tblInvoice AS i INNER JOIN tblCountry AS c ON c.countryID = i.countryID) INNER JOIN tblPartner AS p ON p.partnerID = i.partnerID) INNER JOIN tblUser AS u ON u.userID = i.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) LEFT JOIN tblInvoiceCredit ic ON ic.invoiceID = i.invoiceID) WHERE i.invoiceID IN (" & strInvoiceID & ")"
                invoiceHeadline = "INVOICE"
                plusOrMinus = 1
            ElseIf invoiceType = 2 Then 
                strSql = "SELECT i.invoicePriceListModificationID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoicePrinted, i.date, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM ((((tblInvoicePriceListModification AS i INNER JOIN tblCountry AS c ON c.countryID = i.countryID) INNER JOIN tblPartner AS p ON p.partnerID = i.partnerID) INNER JOIN tblUser AS u ON u.userID = i.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) WHERE i.invoicePriceListModificationID IN (" & strInvoiceID & ")"
                invoiceHeadline = "INVOICE"
                plusOrMinus = 1
            ElseIf invoiceType = 3 Then 
                strSql = "SELECT i.invoiceDurationPenaltyID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoiceText, i.date, v.regnr, v.vinNumber, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM (((((tblInvoiceDurationPenalty AS i INNER JOIN tblVehicle AS v ON v.vehicleID = i.vehicleID) INNER JOIN tblCountry AS c ON c.countryID = v.countryID) INNER JOIN tblPartner AS p ON p.partnerID = v.partnerID) INNER JOIN tblUser AS u ON u.userID = v.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) WHERE i.invoiceDurationPenaltyID IN (" & strInvoiceID & ")"
                invoiceHeadline = "INVOICE"
                plusOrMinus = 1
            ElseIf invoiceType = 4 Then 
                strSql = "SELECT i.invoiceCreditDurationPenaltyID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoiceText, i.date, v.regnr, v.vinNumber, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM (((((tblInvoiceCreditDurationPenalty AS i INNER JOIN tblVehicle AS v ON v.vehicleID = i.vehicleID) INNER JOIN tblCountry AS c ON c.countryID = v.countryID) INNER JOIN tblPartner AS p ON p.partnerID = v.partnerID) INNER JOIN tblUser AS u ON u.userID = v.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) WHERE i.invoiceCreditDurationPenaltyID IN (" & strInvoiceID & ")"
                invoiceHeadline = "CREDIT INVOICE"
                plusOrMinus = - 1
            ElseIf invoiceType = 5 Then 
                strSql = "SELECT i.invoiceDistancePenaltyID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoiceText, i.date, v.regnr, v.vinNumber, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM (((((tblInvoiceDistancePenalty AS i INNER JOIN tblVehicle AS v ON v.vehicleID = i.vehicleID) INNER JOIN tblCountry AS c ON c.countryID = v.countryID) INNER JOIN tblPartner AS p ON p.partnerID = v.partnerID) INNER JOIN tblUser AS u ON u.userID = v.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) WHERE i.invoiceDistancePenaltyID IN (" & strInvoiceID & ")"
                invoiceHeadline = "INVOICE"
                plusOrMinus = 1
            ElseIf invoiceType = 6 Then 
                strSql = "SELECT i.invoiceCreditDistancePenaltyID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoiceText, i.date, v.regnr, v.vinNumber, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM (((((tblInvoiceCreditDistancePenalty AS i INNER JOIN tblVehicle AS v ON v.vehicleID = i.vehicleID) INNER JOIN tblCountry AS c ON c.countryID = v.countryID) INNER JOIN tblPartner AS p ON p.partnerID = v.partnerID) INNER JOIN tblUser AS u ON u.userID = v.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) WHERE i.invoiceCreditDistancePenaltyID IN (" & strInvoiceID & ")"
                invoiceHeadline = "CREDIT INVOICE"
                plusOrMinus = - 1
            ElseIf invoiceType = 7 Then 
                strSql = "SELECT i.invoiceAdminFeeID As invoiceID, i.invoiceID as orgInvoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoicePrinted, i.date, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM ((((tblInvoiceAdminFee AS i INNER JOIN tblCountry AS c ON c.countryID = i.countryID) INNER JOIN tblPartner AS p ON p.partnerID = i.partnerID) INNER JOIN tblUser AS u ON u.userID = i.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) WHERE i.invoiceAdminFeeID IN (" & strInvoiceID & ")"
                invoiceHeadline = "INVOICE"
                plusOrMinus = 1
            ElseIf invoiceType = 8 Then 
                strSql = "SELECT i.invoiceServiceAccountBalanceID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoicePrinted, i.invoiceText, i.date, v.regnr, v.vinNumber, v.contractNumber, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM (((((tblInvoiceServiceAccountBalance AS i INNER JOIN tblVehicle AS v ON v.vehicleID = i.vehicleID) INNER JOIN tblCountry AS c ON c.countryID = v.countryID) INNER JOIN tblPartner AS p ON p.partnerID = v.partnerID) INNER JOIN tblUser AS u ON u.userID = v.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) WHERE i.invoiceServiceAccountBalanceID IN (" & strInvoiceID & ")"
                invoiceHeadline = "INVOICE"
                plusOrMinus = 1
            ElseIf invoiceType = 9 Then 
                strSql = "SELECT i.invoiceCreditServiceAccountBalanceID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoicePrinted, i.invoiceText, i.date, v.regnr, v.vinNumber, v.contractNumber, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM (((((tblInvoiceCreditServiceAccountBalance AS i INNER JOIN tblVehicle AS v ON v.vehicleID = i.vehicleID) INNER JOIN tblCountry AS c ON c.countryID = v.countryID) INNER JOIN tblPartner AS p ON p.partnerID = v.partnerID) INNER JOIN tblUser AS u ON u.userID = v.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) WHERE i.invoiceCreditServiceAccountBalanceID IN (" & strInvoiceID & ")"
                invoiceHeadline = "CREDIT INVOICE"
                plusOrMinus = - 1
            ElseIf invoiceType = 10 Then 
                strSql = "SELECT i.invoiceSeparateID As invoiceID, i.invoiceAmount, i.invoiceClaim, i.invoiceDate, i.expiryDate, i.paymentTerm, i.invoicePrinted, i.invoiceText, i.date, v.regnr, v.vinNumber, v.contractNumber, c.countryID, c.country, c.countryCurrency, c.countryCode, c.decimals, p.partnerID, p.partnerName, p.street, p.zipcode, p.city, u.username, co.bankType, co.accountNumber, co.cin, co.vat, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= i.invoiceDate Order By st.date desc) As salesTax FROM (((((tblInvoiceSeparate AS i INNER JOIN tblCountry AS c ON c.countryID = i.countryID) INNER JOIN tblPartner AS p ON p.partnerID = i.partnerID) INNER JOIN tblUser AS u ON u.userID = i.userID) INNER JOIN tblCompany co ON co.countryID = c.countryID) LEFT JOIN tblVehicle AS v ON v.vehicleID = i.vehicleID) WHERE i.invoiceSeparateID IN (" & strInvoiceID & ")"
                invoiceHeadline = "INVOICE"
                plusOrMinus = 1
            End IF
            dbOpen()
            RS = Conn.Execute("" & strSql & "")
            If Not RS.EOF Then 
                Do Until RS.EOF
                    invoiceID = RS.Fields("invoiceID").Value
                    If invoiceType = 7 Then 
                        orgInvoiceID = RS.Fields("orgInvoiceID").Value
                    End IF
                    invoiceAmount = RS.Fields("invoiceAmount").Value
                    invoiceClaim = RS.Fields("invoiceClaim").Value
                    invoiceDate = RS.Fields("invoiceDate").Value
                    expiryDate = RS.Fields("expiryDate").Value
                    paymentTerm = RS.Fields("paymentTerm").Value
                    If invoiceType = 3 Or invoiceType = 4 Or invoiceType = 5 Or invoiceType = 6 Or invoiceType = 8 Or invoiceType = 9 Or invoiceType = 10 Then 
                        invoiceText = RS.Fields("invoiceText").Value
                    Else
                        invoiceText = ""
                    End IF
                    __date = RS.Fields("date").Value
                    If invoiceType = 3 Or invoiceType = 4 Or invoiceType = 5 Or invoiceType = 6 Or invoiceType = 8 Or invoiceType = 9 Or invoiceType = 10 Then 
                        regnr = RS.Fields("regnr").Value
                        vinNumber = RS.Fields("vinNumber").Value
                    Else
                        regnr = ""
                        vinNumber = ""
                    End IF
                    countryID = RS.Fields("countryID").Value
                    country = RS.Fields("country").Value
                    countryCurrency = RS.Fields("countryCurrency").Value
                    countryCode = RS.Fields("countryCode").Value
                    decimals = RS.Fields("decimals").Value
                    partnerID = RS.Fields("partnerID").Value
                    partnerName = RS.Fields("partnerName").Value
                    street = RS.Fields("street").Value
                    zipcode = RS.Fields("zipcode").Value
                    city = RS.Fields("city").Value
                    username = RS.Fields("username").Value
                    bankType = RS.Fields("bankType").Value
                    __date = RS.Fields("date").Value
                    accountNumber = RS.Fields("accountNumber").Value
                    cin = RS.Fields("cin").Value
                    vat = RS.Fields("vat").Value
                    If invoiceType = 1 Then 
                        invoiceCreditAmount = RS.Fields("invoiceCreditAmount").Value
                    End IF
                    salesTax = RS.Fields("salesTax").Value
                    
                    '**********************
                    If countryID = 4 Then
                        If (__date <= Date.Parse("2010-06-30")) Then
                            salesTax = 22
                        ElseIf (__date > Date.Parse("2010-06-30") And __date < Date.Parse("2013-01-08")) Then
                            salesTax = 23
                        Else
                            salesTax = 24
                        End If
                    End If
                    '**********************
                    
                    If invoiceType = 1 Then 
                        vehicleCount = 0
                        invoiceText = ""
                        RecSet = Conn.Execute("Select vehicleID From tblInvoiceContent Where invoiceID = " & invoiceID & " Group By vehicleID")
                        If Not RecSet.EOF Then 
                            Do Until RecSet.EOF
                                vehicleCount = vehicleCount + 1
                                RecSet.MoveNext()
                            Loop
                        End IF
                        RecSet.Close()
                        RecSet = Nothing
                        vehicleCreditCount = 0
                        RecSet = Conn.Execute("Select vehicleID From (tblInvoiceCredit ic INNER JOIN tblInvoiceCreditContent icc ON icc.invoiceCreditID = ic.invoiceCreditID) Where ic.invoiceID = " & invoiceID & " Group By vehicleID")
                        If Not RecSet.EOF Then 
                            Do Until RecSet.EOF
                                vehicleCreditCount = vehicleCreditCount + 1
                                RecSet.MoveNext()
                            Loop
                        End IF
                        RecSet.Close()
                        RecSet = Nothing
                        If IsDBNull(invoiceCreditAmount) = false Then 
                            invoiceAmount = CDbl(invoiceAmount) - CDbl(invoiceCreditAmount)
                            invoiceClaim = CDbl(invoiceClaim) - CDbl(invoiceCreditAmount)
                        End IF
                        invoiceText = "This invoice is based on " & vehicleCount & " lease contract(s)"
                        If vehicleCreditCount > 0 Then 
                            invoiceText = invoiceText & ", and " & vehicleCreditCount & " credited lease contract(s)"
                        End IF
                        invoiceText = invoiceText & ".<br>For more details, please see the attached specification."
                    ElseIf invoiceType = 2 Then 
                        vehicleCount = 0
                        invoiceText = ""
                        RecSet = Conn.Execute("Select vehicleID From tblInvoicePriceListModificationContent Where invoicePriceListModificationID = " & invoiceID & " Group By vehicleID")
                        If Not RecSet.EOF Then 
                            Do Until RecSet.EOF
                                vehicleCount = vehicleCount + 1
                                RecSet.MoveNext()
                            Loop
                        End IF
                        RecSet.Close()
                        RecSet = Nothing
                        invoiceText = "This invoice is based on " & vehicleCount & " lease contracts due to price modification.<br>For more details, please see the attached specification."
                    ElseIf invoiceType = 7 Then 
                        vehicleCount = 0
                        invoiceText = ""
                        RecSet = Conn.Execute("Select vehicleID From tblInvoiceContent Where invoiceID = " & orgInvoiceID & " Group By vehicleID")
                        If Not RecSet.EOF Then 
                            Do Until RecSet.EOF
                                vehicleCount = vehicleCount + 1
                                RecSet.MoveNext()
                            Loop
                        End IF
                        RecSet.Close()
                        RecSet = Nothing
                        invoiceText = "This administration fee invoice is based on the lease invoice ID " & orgInvoiceID & ", which contains " & vehicleCount & " lease contract(s).<br>For more details, please see the attached specification"
                    End IF
                    salesTaxAmount = 0
                    salesTaxAmount = (CDbl(invoiceAmount) * CDbl(salesTax)) / 100
                    invoiceAmount = invoiceAmount + salesTaxAmount
                    invoiceAmount = FormatNumber(CDbl(invoiceAmount), decimals)
                    CompanyAddressPrintAllSQL()
                    Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%' style='page-break-after: always'>")
                    Response.Write("<tr>")
                    Response.Write("<td colspan='3'>")
                    CompanyAddress()
                    Response.Write("</td>")
                    Response.Write("<td colspan='2'>")
                    Response.Write("<table cellpadding='2' cellspacing='0'>")
                    Response.Write("<tr><td valign='top' class='printBold'>" & partnerName & "</td></tr>")
                    Response.Write("<tr><td valign='top' class='printRegular'>" & street & "</td></tr>")
                    Response.Write("<tr><td valign='top' class='printRegular'>" & countryCode & "-" & zipcode & " " & city & "</td></tr>")
                    Response.Write("</table>")
                    Response.Write("</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr>")
                    Response.Write("<td class='headlineBig' colspan='5' align='center'>")
                    Response.Write(invoiceHeadline)
                    If subDo = "invoiceCopy" Then 
                        Response.Write(" - COPY")
                    End IF
                    Response.Write("</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Customer number</td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Invoice number</td>")
                    Response.Write("<td width='30'></td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Date of invoice</td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Date of expiration</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr>")
                    Response.Write("<td width='125' valign='top' class='printRegular'>" & partnerID & "</td>")
                    Response.Write("<td width='125' valign='top' class='printRegular'>" & invoiceID & "</td>")
                    Response.Write("<td width='30'></td>")
                    Response.Write("<td width='125' valign='top' class='printRegular'>" & invoiceDate & "</td>")
                    Response.Write("<td width='125' valign='top' class='printRegular'>" & expiryDate & "</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Our referee</td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Vehicle</td>")
                    Response.Write("<td width='30'></td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>" & bankType & "</td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Payment term</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr>")
                    Response.Write("<td width='125' valign='top' class='printRegular'>" & username & "</td>")
                    Response.Write("<td width='125' valign='top' class='printRegular'>" & regnr & "<br>" & vinNumber & "</td>")
                    Response.Write("<td width='30'></td>")
                    Response.Write("<td width='125' valign='top' class='printRegular'>" & accountNumber & "</td>")
                    Response.Write("<td width='125' valign='top' class='printRegular'>" & paymentTerm & "</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr>")
                    Response.Write("<td colspan='5'>")
                    Response.Write("<table class='fullFrame' width='100%' cellpadding='3' cellspacing='0' height='200'>")
                    Response.Write("<tr>")
                    Response.Write("<td valign='top' class='printRegular'>")
                    Response.Write(invoiceText)
                    Response.Write("</td>")
                    Response.Write("</tr>")
                    Response.Write("</table>")
                    Response.Write("</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr>")
                    Response.Write("<td valign='top' class='printBold' colspan='2'>Corporate identity number</td>")
                    Response.Write("<td width='30'></td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Price:</td>")
                    Response.Write("<td width='125' valign='top' class='printRegular' align='right'>" & FormatNumber((CDbl(invoiceAmount) - salesTaxAmount) * plusOrMinus, 2) & " " & countryCurrency & "</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr>")
                    Response.Write("<td valign='top' class='printRegular' colspan='2'>" & cin & "</td>")
                    Response.Write("<td width='30'></td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>VAT (" & salesTax & "%):</td>")
                    Response.Write("<td width='125' valign='top' class='printRegular' align='right'>" & FormatNumber(salesTaxAmount * plusOrMinus, 2) & " " & countryCurrency & "</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr>")
                    Response.Write("<td valign='top' class='printRegular' colspan='2'></td>")
                    Response.Write("<td width='30'></td>")
                    Response.Write("<td width='125' valign='top' class='printBold'>Invoice amount:</td>")
                    Response.Write("<td width='125' valign='top' class='printRegular' align='right'>" & FormatNumber(CDbl(invoiceAmount) * plusOrMinus, 2) & " " & countryCurrency & "</td>")
                    Response.Write("</tr>")
                    If Len(vat) > 0 Then 
                        Response.Write("<tr>")
                        Response.Write("<td valign='top' class='printBold' colspan='2'>VAT registration number</td>")
                        Response.Write("</tr>")
                        Response.Write("<tr>")
                        Response.Write("<td valign='top' class='printRegular' colspan='2'>" & vat & "</td>")
                        Response.Write("</tr>")
                    End IF
                    Response.Write("</table>")
                    RS.MoveNext()
                Loop
            End IF
            RS.Close()
            RS = Nothing
            dbClose()
        Next
        Under()
    ElseIf Request.QueryString("do") = "printSpecification" Then 
        strInvoiceID = Request.QueryString("strInvoiceID")
%>
<script type="text/javascript">
    function printCheck() {
        if (window.confirm('OBS! Please check all printouts before you press "OK" below.')) {
            location.href = 'printAllInvoice.aspx?do=setAsPrinted&strInvoiceID=<%= strInvoiceID %>';
	}
	else {
	    return false;
	}
}
  </script>
<%
        OverPrint()
        Response.Write("<div class=noprint>")
        Response.Write("<table>")
        Response.Write("<tr>")
        Response.Write("<td class='headline'>")
        Response.Write("<form>")
        Response.Write("<input type='button' onClick='javascript:print();' value='Print'>&nbsp; ")
        Response.Write("<input type='button' value='Set invoices as printed' onclick=""{return printCheck();} return false;"">")
        Response.Write("</form>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Response.Write("</div>")
        vehicleCreditCount = 0
        For invoiceType = 1 To 3
            If invoiceType = 1 Then 
                strSql = "Select i.invoiceID, DATENAME(month, DATEADD(month,-1,i.invoiceDate)) As monthName, DATENAME(year, DATEADD(month,-1,i.invoiceDate)) As yearName, co.countryCurrency, co.decimals, c.invoiceCreditID From ((tblInvoice i INNER JOIN tblCountry co ON co.countryID = i.countryID) LEFT JOIN tblInvoiceCredit c ON c.invoiceID = i.invoiceID) Where i.invoiceID IN (" & strInvoiceID & ") Group By i.invoiceID, i.invoiceDate, co.countryCurrency, co.decimals, c.invoiceCreditID Order By i.invoiceID"
            ElseIf invoiceType = 2 Then 
                strSql = "Select i.invoicePriceListModificationID As invoiceID, DATENAME(month, DATEADD(month,-1,i.invoiceDate)) As monthName, DATENAME(year, DATEADD(month,-1,i.invoiceDate)) As yearName, co.countryCurrency, co.decimals From (tblInvoicePriceListModification i INNER JOIN tblCountry co ON co.countryID = i.countryID) Where i.invoicePriceListModificationID IN (" & strInvoiceID & ") Order By i.invoicePriceListModificationID"
            ElseIf invoiceType = 3 Then 
                strSql = "Select i.invoiceID, DATENAME(month, DATEADD(month,-1,i.invoiceDate)) As monthName, DATENAME(year, DATEADD(month,-1,i.invoiceDate)) As yearName, co.countryCurrency, co.decimals From (tblInvoiceAdminFee i INNER JOIN tblCountry co ON co.countryID = i.countryID) Where i.invoiceID IN (" & strInvoiceID & ") Order By i.invoiceID"
            End IF
            dbOpen()
            RecSet = Conn.Execute("" & strSql & "")
            If Not RecSet.EOF Then 
                Do Until RecSet.EOF
                    invoiceID = RecSet.Fields("invoiceID").Value
                    monthName = RecSet.Fields("monthName").Value
                    yearName = RecSet.Fields("yearName").Value
                    countryCurrency = RecSet.Fields("countryCurrency").Value
                    decimals = RecSet.Fields("decimals").Value
                    If invoiceType = 1 Then 
                        invoiceCreditID = RecSet.Fields("invoiceCreditID").Value
                    End IF
                    If IsDBNull(invoiceCreditID) = true Then 
                        invoiceCreditID = 0
                    End IF
                    Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%' style='page-break-after: always'>")
                    Response.Write("<tr>")
                    Response.Write("<td class='headlineBig' colspan='5' align='center'>")
                    If invoiceType = 1 Then 
                        Response.Write("LEASING SPECIFICATION " & UCase(monthName) & " " & yearName & "")
                    ElseIf invoiceType = 2 Then 
                        Response.Write("PRICE MODIFICATION SPECIFICATION " & UCase(monthName) & " " & yearName & "")
                    ElseIf invoiceType = 3 Then 
                        Response.Write("ADMIN FEE SPECIFICATION " & UCase(monthName) & " " & yearName & "")
                    End IF
                    Response.Write("</td>")
                    Response.Write("</tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr><td><br></td></tr>")
                    Response.Write("<tr>")
                    Response.Write("<td colspan='5'>")
                    Response.Write("<table class='fullFrame' width='100%' cellpadding='3' cellspacing='0' height='100%'>")
                    If invoiceType = 1 Then 
                        Response.Write("<tr valign='top'>")
                        Response.Write("<td class='printBold'>Contract number</td>")
                        Response.Write("<td class='printBold'>Licence number</td>")
                        Response.Write("<td class='printBold'>VIN-number</td>")
                        Response.Write("<td class='printBold'>Product</td>")
                        Response.Write("<td class='printBold'>Period</td>")
                        Response.Write("<td class='printBold'>Duration</td>")
                        Response.Write("<td class='printBold'>Price</td>")
                        Response.Write("<td class='printBold'></td>")
                        Response.Write("</tr>")
                        RS = Conn.Execute("Select ic.leaseCurrentDate, v.contractNumber, v.regnr, v.vinNumber, p.product, pl.price, pl.priceListDuration, (Select Count(ic2.vehicleID) From tblInvoiceContent ic2 Where ic2.vehicleID = ic.vehicleID AND ic2.invoiceID <= ic.invoiceID) As vehicleCount, (Select Sum(ap.price) From (tblInvoiceContentAdditional ica INNER JOIN tblAdditionalProduct ap ON ap.additionalProductID = ica.additionalProductID) Where ica.vehicleID = v.vehicleID And ica.invoiceID = ic.invoiceID) As additionalProductSum From (((tblInvoiceContent ic INNER JOIN tblVehicle v ON v.vehicleID = ic.vehicleID) INNER JOIN tblProduct p ON p.productID = v.productID) INNER JOIN tblPriceList pl ON pl.priceListID = v.priceListID) Where ic.invoiceID = " & invoiceID & " Order By v.contractNumber, ic.leaseCurrentDate")
                        If Not RS.EOF Then 
                            Do Until RS.EOF
                                leaseCurrentDate = RS.Fields("leaseCurrentDate").Value
                                contractNumber = RS.Fields("contractNumber").Value
                                regnr = RS.Fields("regnr").Value
                                vinNumber = RS.Fields("vinNumber").Value
                                product = RS.Fields("product").Value
                                price = RS.Fields("price").Value
                                priceListDuration = RS.Fields("priceListDuration").Value
                                vehicleCount = RS.Fields("vehicleCount").Value
                                additionalProductSum = RS.Fields("additionalProductSum").Value
                                If IsDBNull(additionalProductSum) = true Then 
                                    additionalProductSum = 0
                                End IF
                                price = price + additionalProductSum
                                Response.Write("<tr valign='top'>")
                                Response.Write("<td class='printRegular'>" & contractNumber & "</td>")
                                Response.Write("<td class='printRegular'>" & regnr & "</td>")
                                Response.Write("<td class='printRegular'>" & vinNumber & "</td>")
                                Response.Write("<td class='printRegular'>" & product & "</td>")
                                Response.Write("<td class='printRegular'>" & leaseCurrentDate & "</td>")
                                Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>" & vehicleCount & "/" & priceListDuration & "</td>")
                                Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>" & FormatNumber(CDbl(price), 2) & "</td>")
                                Response.Write("<td class='printRegular' nowrap='nowrap'>" & countryCurrency & "</td>")
                                Response.Write("</tr>")
                                RS.MoveNext()
                            Loop
                        End IF
                        RS.Close()
                        RS = Nothing
                        If CInt(invoiceCreditID) > 0 Then 
                            RS = Conn.Execute("Select ic.leaseCurrentDate, v.contractNumber, v.regnr, v.vinNumber, p.product, pl.price, pl.priceListDuration, (Select Count(ic2.vehicleID) From tblInvoiceContent ic2 Where ic2.vehicleID = ic.vehicleID AND ic2.invoiceID <= ic.invoiceID) As vehicleCount, (Select Sum(ap.price) From (tblInvoiceCreditContentAdditional ica INNER JOIN tblAdditionalProduct ap ON ap.additionalProductID = ica.additionalProductID) Where ica.vehicleID = v.vehicleID And ica.invoiceCreditID = ic.invoiceCreditID) As additionalProductSum From (((tblInvoiceCreditContent ic INNER JOIN tblVehicle v ON v.vehicleID = ic.vehicleID) INNER JOIN tblProduct p ON p.productID = v.productID) INNER JOIN tblPriceList pl ON pl.priceListID = v.priceListID) Where ic.invoiceCreditID = " & invoiceCreditID & " Order By v.contractNumber, ic.leaseCurrentDate")
                            If Not RS.EOF Then 
                                Do Until RS.EOF
                                    leaseCurrentDate = RS.Fields("leaseCurrentDate").Value
                                    contractNumber = RS.Fields("contractNumber").Value
                                    regnr = RS.Fields("regnr").Value
                                    vinNumber = RS.Fields("vinNumber").Value
                                    product = RS.Fields("product").Value
                                    price = RS.Fields("price").Value
                                    priceListDuration = RS.Fields("priceListDuration").Value
                                    vehicleCount = RS.Fields("vehicleCount").Value
                                    additionalProductSum = RS.Fields("additionalProductSum").Value
                                    If IsDBNull(additionalProductSum) = true Then 
                                        additionalProductSum = 0
                                    End IF
                                    price = price + additionalProductSum
                                    Response.Write("<tr valign='top'>")
                                    Response.Write("<td class='printRegular'>" & contractNumber & "</td>")
                                    Response.Write("<td class='printRegular'>" & regnr & "</td>")
                                    Response.Write("<td class='printRegular'>" & vinNumber & "</td>")
                                    Response.Write("<td class='printRegular'>" & product & "</td>")
                                    Response.Write("<td class='printRegular'>" & leaseCurrentDate & "</td>")
                                    Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>" & vehicleCount & "/" & priceListDuration & "</td>")
                                    Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>-" & FormatNumber(CDbl(price), decimals) & "</td>")
                                    Response.Write("<td class='printRegular' nowrap='nowrap'>" & countryCurrency & "</td>")
                                    Response.Write("</tr>")
                                    RS.MoveNext()
                                Loop
                            End IF
                            RS.Close()
                            RS = Nothing
                        End IF
                    ElseIf invoiceType = 2 Then 
                        Response.Write("<tr valign='top'>")
                        Response.Write("<td class='printBold'>Contract number</td>")
                        Response.Write("<td class='printBold'>Licence number</td>")
                        Response.Write("<td class='printBold'>VIN-number</td>")
                        Response.Write("<td class='printBold'>Product</td>")
                        Response.Write("<td class='printBold'>Period</td>")
                        Response.Write("<td class='printBold'>Old price</td>")
                        Response.Write("<td class='printBold'>New price</td>")
                        Response.Write("<td class='printBold'>Difference in prices</td>")
                        Response.Write("<td class='printBold'></td>")
                        Response.Write("</tr>")
                        RS = Conn.Execute("Select iplmc.leaseCurrentDate, v.regnr, v.vinNumber, v.contractNumber, p.product, pl1.price As oldPrice, pl2.price As newPrice From ((((tblInvoicePriceListModificationContent iplmc INNER JOIN tblVehicle v ON v.vehicleID = iplmc.vehicleID) INNER JOIn tblProduct p ON p.productID = v.productID) INNER JOIN tblPriceList pl1 ON pl1.priceListID = iplmc.oldPriceListID) INNER JOIN tblPriceList pl2 ON pl2.priceListID = iplmc.newPriceListID) Where iplmc.invoicePriceListModificationID = " & invoiceID & " Order by v.contractNumber, iplmc.leaseCurrentDate")
                        If Not RS.EOF Then 
                            Do Until RS.EOF
                                leaseCurrentDate = RS.Fields("leaseCurrentDate").Value
                                regnr = RS.Fields("regnr").Value
                                vinNumber = RS.Fields("vinNumber").Value
                                contractNumber = RS.Fields("contractNumber").Value
                                product = RS.Fields("product").Value
                                oldPrice = RS.Fields("oldPrice").Value
                                newPrice = RS.Fields("newPrice").Value
                                leaseCurrentDate = Left(leaseCurrentDate, 7)
                                price = CDbl(newPrice) - CDbl(oldPrice)
                                Response.Write("<tr valign='top'>")
                                Response.Write("<td class='printRegular'>" & contractNumber & "</td>")
                                Response.Write("<td class='printRegular'>" & regnr & "</td>")
                                Response.Write("<td class='printRegular'>" & vinNumber & "</td>")
                                Response.Write("<td class='printRegular'>" & product & "</td>")
                                Response.Write("<td class='printRegular'>" & leaseCurrentDate & "</td>")
                                Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>" & FormatNumber(CDbl(oldPrice), 2) & "</td>")
                                Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>" & FormatNumber(CDbl(newPrice), 2) & "</td>")
                                Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>" & FormatNumber(CDbl(price), 2) & "</td>")
                                Response.Write("<td class='printRegular' nowrap='nowrap'>" & countryCurrency & "</td>")
                                Response.Write("</tr>")
                                RS.MoveNext()
                            Loop
                        End IF
                        RS.Close()
                        RS = Nothing
                    ElseIf invoiceType = 3 Then 
                        Response.Write("<tr valign='top'>")
                        Response.Write("<td class='printBold'>Contract number</td>")
                        Response.Write("<td class='printBold'>Licence number</td>")
                        Response.Write("<td class='printBold'>VIN-number</td>")
                        Response.Write("<td class='printBold'>Product</td>")
                        Response.Write("<td class='printBold'>Period</td>")
                        Response.Write("<td class='printBold'>Duration</td>")
                        Response.Write("<td class='printBold'>Admin fee</td>")
                        Response.Write("<td class='printBold'></td>")
                        Response.Write("</tr>")
                        RS = Conn.Execute("Select ic.leaseCurrentDate, v.contractNumber, v.regnr, v.vinNumber, p.product, pl.adminFee, pl.priceListDuration, (Select Count(ic2.vehicleID) From tblInvoiceContent ic2 Where ic2.vehicleID = ic.vehicleID AND ic2.invoiceID <= ic.invoiceID) As vehicleCount From (((tblInvoiceContent ic INNER JOIN tblVehicle v ON v.vehicleID = ic.vehicleID) INNER JOIN tblProduct p ON p.productID = v.productID) INNER JOIN tblPriceList pl ON pl.priceListID = v.priceListID) Where ic.invoiceID = " & invoiceID & " Order By v.contractNumber, ic.leaseCurrentDate")
                        If Not RS.EOF Then 
                            Do Until RS.EOF
                                leaseCurrentDate = RS.Fields("leaseCurrentDate").Value
                                contractNumber = RS.Fields("contractNumber").Value
                                regnr = RS.Fields("regnr").Value
                                vinNumber = RS.Fields("vinNumber").Value
                                product = RS.Fields("product").Value
                                adminFee = RS.Fields("adminFee").Value
                                priceListDuration = RS.Fields("priceListDuration").Value
                                vehicleCount = RS.Fields("vehicleCount").Value
                                Response.Write("<tr valign='top'>")
                                Response.Write("<td class='printRegular'>" & contractNumber & "</td>")
                                Response.Write("<td class='printRegular'>" & regnr & "</td>")
                                Response.Write("<td class='printRegular'>" & vinNumber & "</td>")
                                Response.Write("<td class='printRegular'>" & product & "</td>")
                                Response.Write("<td class='printRegular'>" & leaseCurrentDate & "</td>")
                                Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>" & vehicleCount & "/" & priceListDuration & "</td>")
                                Response.Write("<td align='right' class='printRegular' nowrap='nowrap'>" & FormatNumber(CDbl(adminFee), decimals) & "</td>")
                                Response.Write("<td class='printRegular' nowrap='nowrap'>" & countryCurrency & "</td>")
                                Response.Write("</tr>")
                                RS.MoveNext()
                            Loop
                        End IF
                        RS.Close()
                        RS = Nothing
                    End IF
                    Response.Write("<tr><td height='100%'></td></tr>")
                    Response.Write("</table>")
                    Response.Write("</td>")
                    Response.Write("</tr>")
                    Response.Write("</table>")
                    RecSet.MoveNext()
                Loop
            End IF
            RecSet.Close()
            RecSet = Nothing
            dbClose()
        Next
        Under()
    ElseIf Request.QueryString("do") = "setAsPrinted" Then 
        strInvoiceID = Request.QueryString("strInvoiceID")
        dbOpen()
        Conn.Execute("Update tblInvoice Set invoicePrinted = 1 Where invoiceID IN (" & strInvoiceID & ")")
        Conn.Execute("Update tblInvoiceCredit Set invoicePrinted = 1 Where invoiceID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoicePriceListModification Set invoicePrinted = 1 Where invoicePriceListModificationID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoiceDurationPenalty Set invoicePrinted = 1 Where invoiceDurationPenaltyID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoiceCreditDurationPenalty Set invoicePrinted = 1 Where invoiceCreditDurationPenaltyID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoiceDistancePenalty Set invoicePrinted = 1 Where invoiceDistancePenaltyID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoiceCreditDistancePenalty Set invoicePrinted = 1 Where invoiceCreditDistancePenaltyID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoiceAdminFee Set invoicePrinted = 1 Where invoiceAdminFeeID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoiceServiceAccountBalance Set invoicePrinted = 1 Where invoiceServiceAccountBalanceID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoiceCreditServiceAccountBalance Set invoicePrinted = 1 Where invoiceCreditServiceAccountBalanceID IN (" & strInvoiceID & ")")
        dbOpen()
        dbOpen()
        Conn.Execute("Update tblInvoiceSeparate Set invoicePrinted = 1 Where invoiceSeparateID IN (" & strInvoiceID & ")")
        dbOpen()
        Response.Redirect("printAllInvoice.aspx?do=done")
    ElseIf Request.QueryString("do") = "done" Then 
        Over()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='100%'>")
        Response.Write("<tr>")
        Response.Write("<td>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='100%'>")
        Response.Write("<tr>")
        Response.Write("<td class='headline'>QUEUED PRINTOUTS<hr class='hrHeadline'></td>")
        Response.Write("</tr>")
        Response.Write("<tr>")
        Response.Write("<td>All invoice(s) are set as printed.</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
End If
%>

